﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.IO;
using System.Threading.Tasks;

namespace OutillageTests
{
    public class Entry
    {
        public Entry()
        {
        }

        public void LaunchTUGenerator()
        {
            Dictionary<Type, Dictionary<MethodInfo, bool>> carto = new Dictionary<Type, Dictionary<MethodInfo, bool>>();

            // Gestion des répertoires
            if (!Directory.Exists(@"C:\Generation TU\"))
            {
                Directory.CreateDirectory(@"C:\Generation TU\");
                Directory.CreateDirectory(@"C:\Generation TU\TUXML\");
                Directory.CreateDirectory(@"C:\Generation TU\ClassesTU\");
            }
            
            string[] files = Directory.GetFiles("C:/TFS/Pleiade/Fwk/Main/Metier/Bin", 
                "Adp.Pleiade.Metier*Services*.dll");

            // Uniquement Services Gestion Dossier FSS
           // string[] files = Directory.GetFiles("C:/TFS/Pleiade/Fwk/Main/Metier/Bin",
            //    "Adp.Pleiade.Metier.GroupePrestationsFSS.GestiondossierFSS.Services.dll");

            try
            {
                Parallel.ForEach(files, file =>
                {
                    Assembly assembly = Assembly.LoadFile(file);
                    Parallel.ForEach(assembly.GetExportedTypes(), classe =>
                    {
                        // Test des Services uniquement
                        //if (typeof(AncestorService).IsAssignableFrom(classe))
                        //{
                        ClassParser parser = new ClassParser(classe);
                        carto.Add(classe, parser.ParseClass());
                        //}
                    });
                });

            }
            catch
            {
                // Génération du rapport CSV
                ReportingManager report = new ReportingManager(@"C:\Generation TU\Rapport.csv", carto);
                report.CreerRapport();

                // Génération des fichiers XML
                carto = GenerationXML.GenererXML(@"C:\Generation TU\TUXML\", carto);

                // Génération des classes de tests
                GenerationClasseTU.GenererClassesTU(@"C:\Generation TU\ClassesTU\", carto);
            }
        }
    }
}
